<template>
	<view class="page-body">
		<el-row :gutter="15">
			<el-form ref="form1" :model="form1" :rules="rules" size="medium" label-width="100px">
				<el-col :span="24">
					<el-form-item label="图片" prop="url" required>
						<vk-data-input-file-select v-model="form1.url" placeholder="请选择图片" file-type="image">
						</vk-data-input-file-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="标题" prop="title">
						<el-input v-model="form1.title" placeholder="请输入标题" clearable :style="{width: '100%'}">
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="内容" prop="content">
						<vk-data-input-editor v-model="form1.content" placeholder="请输入内容" width="100%">
						</vk-data-input-editor>
					</el-form-item>
				</el-col>

				<el-col :span="24">
					<el-form-item size="large">
						<el-button type="primary" @click="submitForm">提交</el-button>
						<el-button @click="resetForm">重置</el-button>
					</el-form-item>
				</el-col>
			</el-form>
		</el-row>
	</view>
</template>
<script>
	var that; // 当前页面对象
	var vk = uni.vk; // vk实例
	export default {
		props: ['action', 'form-type', 'item'],
		components: {},
		data() {
			return {
				form1: {
					url: null,
					type: null,
					title: '',
					content: null,
					sort: 1,
					show: 1,
				},
				rules: {
					title: [{
						required: true,
						message: '请输入说明标题',
						trigger: 'blur'
					}],
					type: [{
						required: true,
						message: '请选择说明类型',
						trigger: 'blur'
					}],
					content: [{
						required: true,
						message: '请输入说明内容',
						trigger: 'blur'
					}],
					sort: [{
						required: true,
						message: '请输入排序',
						trigger: 'blur'
					}],
					show: [{
						required: true,
						message: '请选择是否显示',
						trigger: 'blur'
					}]
				},
				types: [{
					"label": "政策",
					"value": 1
				}, {
					"label": "说明",
					"value": 2
				}],
				is_show: [{
					"label": "是",
					"value": true
				}, {
					"label": "否",
					"value": false
				}]
			}
		},
		//监听-页面每次【加载时】执行(如:前进)
		onLoad(options = {}) {},
		created() {
			that = this;
			vk = that.vk;
			if (this.formType == "update") {
				this.form1 = this.item
			}
		},
		mounted() {},
		methods: {
			//页面数据初始化函数
			init(options) {},
			submitForm() {
				this.$refs['form1'].validate(valid => {
					if (!valid) return
					vk.callFunction({
						url: this.action,
						title: '提交中...',
						data: this.form1,
						success(data) {
							that.$emit("success")
						}
					});
				})
			},
			resetForm() {
				this.$refs['form1'].resetFields()
			}
		},
		// 监听器
		watch: {},
		// 过滤器
		filters: {},
		// 计算属性
		computed: {},
	}
</script>
<style lang="scss" scoped>
	.el-upload__tip {
		line-height: 1.2;
	}

	.page-body {
		max-width: 1200px !important;
		margin: 0 auto;
	}
</style>
